// pages/pillow/pillow.js
Page({
  data: {
    currentList: 0,
    list: [{
        text: '睡眠质量',
        index: 0
      },
      {
        text: '睡姿分布',
        index: 1
      },
    ],
    list1: [],
    list2: [],
  },
  comNumFn(cleanHex) {
    //计算数据
    const bitArray = [];
    for (let i = 0; i < cleanHex.length; i += 2) {
      const byteStr = cleanHex.substr(i, 2);
      const bits = parseInt(byteStr, 16)
        .toString(2)
        .padStart(8, '0') // 图片说明：每个FF代表8位
        .split('')
      bitArray.push(...bits);
    }
    console.log('bitArray',bitArray);
    return bitArray;
  },
  init(cmd, list) {
    if (cmd == 'RED:02') {
      this.setData({
        list1: list,
      }, () => {
        let sm1List = this.data.list1[0].split('');
        console.log('sm1List',sm1List);
        let child = this.selectComponent('#sleepQuality');
        child && child.init(sm1List);
      })
    }
    if (cmd == 'RED:03') {
      this.setData({
        list2: list,
      })
    }
  },
  changeTabFn(item) {
    let {
      index
    } = item.currentTarget.dataset.item;
    this.setData({
      currentList: index,
    }, () => {
      if (index == 0) {
        let sm1List = this.data.list1[0].split('');
        let child = this.selectComponent('#sleepQuality');
        child && child.init(sm1List);
      } else {
        let sm2List = this.data.list2[0].split('');
        let child = this.selectComponent('#distributionSleep');
        child && child.init(sm2List);
      }
    })
  },
});